package com.example.aiadmin.util;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;


public class AiReviewUtil {
    public GenerationResult review(String message) throws ApiException, NoApiKeyException, InputRequiredException {
        //
        System.out.println(message);
        Generation gen = new Generation();
        String prompt = "角色：微博审核员；\n" +
                "任务：你将对用户发表的待审核的微博列表进行审核，审核该微博的内容及标题是否包含敏感和非法的词句，自动更改该微博的状态：如果确定非法，则为-1(禁止发表)，" +
                "如果判定为可能非法，则自动更改为3（人工审核)，如果符合要求则设置为1(正常)。最后的返回只需返回按提交的微博顺序的state值的一个List,不用返回其他字段，请使用json格式，\n" +
                "返回例子如下：[\n" +
                "  1,  \n" +
                "  -1 \n" +
                "]。。";
        QwenParam params = QwenParam.builder().model("qwen-plus")
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .prompt(prompt+"微博如下："+message)
                .seed(1234)
                .topP(0.8)
                .resultFormat("message")
                .enableSearch(false)
                .maxTokens(1500)
                .temperature((float)0.85)
                .repetitionPenalty((float)1.0)
                .build();
        GenerationResult result = gen.call(params);
        //String answer = result.getOutput().getChoices().get(0).getMessage().getContent();
        return result;
    }

}
